/*
 * Copyright (C) 2020 The LINN Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package com.juqimiao.linn.transfer.query.builders;

import com.juqimiao.linn.transfer.Response;

/**
 * 表示构建响应对象的构建者类。
 *
 * @author  Collin Cai
 */
public class ResponseBuilder extends BaseResponseBuilder<Response> {

    /**
     * 构造函数。
     */
    public ResponseBuilder() {
        super();
    }

    /**
     * 构建包含成功状态的响应对象。
     *
     * @param successfulMessage 可选，成功信息。
     * @return 一个响应构建者对象。
     */
    public ResponseBuilder success(String successfulMessage) {
        getResponse().makeSuccess(successfulMessage);
        return this;
    }

    /**
     * 构建包含成功状态的响应对象。
     *
     * @return 一个响应构建者对象。
     */
    public ResponseBuilder success() {
        getResponse().makeSuccess(null);
        return this;
    }

    /**
     * 构建包含错误的响应对象。
     *
     * @param errorCode    错误代码。
     * @param errorMessage 错误信息。
     * @return 一个响应对象。
     */
    public Response failure(String errorCode, String errorMessage) {
        getResponse().makeFailure(errorCode, errorMessage);
        return super.build();
    }

    /**
     * 获得一个构建响应构建对象。
     *
     * @return 一个构建响应对象的构造者对象。
     */
    public static ResponseBuilder builder() {
        ResponseBuilder builder = new ResponseBuilder();
        builder.setResponse(new Response());
        return builder;
    }
}

